/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.documents.main.action;

import com.documents.common.core.PageBean;
import com.documents.common.core.action.BaseActionSupport;
import com.documents.pojo.Product;
import com.documents.service.product.ProductService;

import java.util.List;
import org.apache.struts2.interceptor.ServletRequestAware;

/**
 *
 * @author sunying
 */
public class ProductAction extends BaseActionSupport implements ServletRequestAware {

    private static final long serialVersionUID = 1003L;
    private ProductService productService;
    private List<Product> allProduct;
  
    private Integer flag = 0;
    private Integer pid = 0;
    private int page=1;
    private PageBean pageBean;
    private int pageSize = 20;
    private Product product;

 
    private String jsonDataString;
    private String actionURI;
       

    public String getActionURI() {
        return this.actionURI;
    }

    public void setActionURI(String actionURI) {
        this.actionURI = actionURI;
    }

    public List<Product> getAllProduct() {
        return this.allProduct;
    }

    public void setAllProduct(List<Product> allProduct) {
        this.allProduct = allProduct;
    }

    public Integer getFlag() {
        return this.flag;
    }

    public void setFlag(Integer flag) {
        this.flag = flag;
    }

    public String getJsonDataString() {
        return this.jsonDataString;
    }

    public void setJsonDataString(String jsonDataString) {
        this.jsonDataString = jsonDataString;
    }

    public int getPage() {
        return this.page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public PageBean getPageBean() {
        return this.pageBean;
    }

    public void setPageBean(PageBean pageBean) {
        this.pageBean = pageBean;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPid() {
        return this.pid;
    }

    public void setPid(Integer parentId) {
        this.pid = parentId;
    }

    public Product getProduct() {
        return this.product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public ProductService getProductService() {
        return this.productService;
    }

    public void setProductService(ProductService productService) {
        this.productService = productService;
    }
    
    
    public String main() throws Exception {
        return "success";
    }

    public String top() throws Exception {
        this.allProduct = productService.findAll();
        return "success";
    }

    public String list() throws Exception {

        pageBean = productService.getPageBean(page, pageSize, product);

        return SUCCESS;
    }
    
     public void deleteById() {
        
        productService.deleteById(product.getId());
    }

    public String addInput() throws Exception {
        actionURI = "save";
        return SUCCESS;
    }

    public String save() throws Exception {
        productService.saveInstance(product);
        return SUCCESS;
    }
    
     public String update() throws Exception {
        productService.update(product);
        return SUCCESS;
    }
    
    public String updateInput() throws Exception {
        actionURI = "update";
        product = this.productService.get(product.getId());
        if(product == null)
            return ERROR;
        else
            return SUCCESS;
    }
    

  
}


